import { param2Obj } from '@/utils'

const userMap = {
  admin: {
    code: 0,
    data: {
      token: 'admin',
      rules: {
        page: {
          Layout: true,
          home: true,
          home_index: true,
          testA: false,
          testA_1: false,
          testB: true,
          testB_1: true,
          testB_2: false
        },
        component: {
          edit_button: true,
          publish_button: false
        }
      }
    }
  }
}

export default {
  loginByUsername: config => {
    const { username } = JSON.parse(config.body)
    return userMap[username]
  },
  getUserInfo: config => {
    const { token } = param2Obj(config.url)
    if (userMap[token]) {
      return userMap[token]
    } else {
      return false
    }
  },
  logout: () => {
    return {
      code: 0,
      Message: 'success'
    }
  }
}
